import json
import requests
import web


# render = web.template.render('static/')


class index:
    def GET(self):
        # sql = "select id , name , age from user"
        # db.cursor.execute(sql)
        # todos = db.cursor.fetchall()
        result = {
            'name': '产品综合应用平台',
            'describe': '产品综合应用平台 :用于各产品展示，安装包下载及相关文档的在线展示',
        };

        web.header('Content-Type', 'text/html;charset=UTF-8')
        return json.dumps(result)


class one:
    def GET(self):
        raise web.seeother('/static/index.html')


class test:
    def GET(self):
        url = "http://www.nmc.cn/f/rest/real/54399?_=1574654239895"
        req = requests.get(url).json()
        info = {
            "region": req["station"]["province"] + req["station"]["city"] + "区",
            "time": req["publish_time"],
            "temperature": req["weather"]["temperature"],
        }
        web.header('Content-Type', 'text/html;charset=UTF-8')
        return json.dumps(info)


class add:
    def POST(self):
        i = web.input()
        print(i['title'])
        # 重定向
        raise web.seeother('/')
